package ru.cybertek.domain;

import java.math.BigDecimal;
import java.util.Currency;

import ru.cybertek.domain.constant.AccountType;

/**
 * @author Dmitry Demyankov
 * @version $Revision: 51 $
 * 
 *         (C) Copyright 2009 CyberTek Ltd. All rights reserved.
 */
public class Account extends StoredEntity
{
    private Bank bank;

    private StoredEntity owner;

    private String accountNumber;

    private Double balance;

    private Currency currency;

    /**
     * Default constructor.
     */
    public Account() {}
    
    /**
     * Constructor to set id
     * 
     * @param id - record id in db
     */
    public Account(Integer id)
    {
    	super.setId(id);
    }

    /**
     * Returns type of current account based on owner type.
     * 
     * @return {@link ru.cybertek.domain.constant.AccountType}
     */
    public AccountType getAccountType()
    {
        AccountType type = null;

        if (owner instanceof Company)
            type = AccountType.CORPORATE;
        else if (owner instanceof Person)
            type = AccountType.PERSONAL;

        return type;
    }

    /**
     * Getter for property accountNumber.
     * 
     * @return the accountNumber
     */
    public String getAccountNumber()
    {
        return accountNumber;
    }

    /**
     * Setter for property accountNumber.
     * 
     * @param accountNumber
     *            the accountNumber to set
     */
    public void setAccountNumber(String accountNumber)
    {
        this.accountNumber = accountNumber;
    }

    /**
     * Getter for property bank.
     * 
     * @return the bank
     */
    public Bank getBank()
    {
        return bank;
    }

    /**
     * Setter for property bank.
     * 
     * @param bank
     *            the bank to set
     */
    public void setBank(Bank bank)
    {
        this.bank = bank;
    }
    
    public void setBank(Integer id)
    {
    	this.bank = new Bank(id);
    }

    /**
     * Getter for property balance.
     * 
     * @return the balance
     */
    public Double getBalance()
    {
        return balance;
    }

    /**
     * Setter for property balance.
     * 
     * @param balance
     *            the balance to set
     */
    public void setBalance(Double balance)
    {
        this.balance = balance;
    }

    /**
     * Getter for property owner.
     * 
     * @return the owner
     */
    public StoredEntity getOwner()
    {
        return owner;
    }

    /**
     * Setter for property owner.
     * 
     * @param owner
     *            the owner to set
     */
    public void setOwner(StoredEntity owner)
    {
        this.owner = owner;
    }

    /**
     * Getter for property currency.
     * 
     * @return the currency
     */
    public Currency getCurrency()
    {
        return currency;
    }

    /**
     * Setter for property currency.
     * 
     * @param currency
     *            the currency to set
     */
    public void setCurrency(Currency currency)
    {
        this.currency = currency;
    }
}
